#pragma once

class Camera;
class CheckersBoard;
class CheckersPiece;

#include <vector>
#include "D3DApp.h"
#include "DirectXMath.h"
#include "Animation.h"

class CheckersApp : public D3DApp
{
	// Fields
	std::vector<Animation*> animations;
	Camera *camera;
	ID3D11Buffer *cbPerObject;
	CheckersBoard *checkersBoard;
	CheckersPiece *blackPiece, *redPiece;
	ID3D11Buffer *ibBlock;
	ID3D11Buffer *ibCylinder;
	ID3D11InputLayout *inputLayout;
	DirectX::XMMATRIX projMatrix;
	ID3D11PixelShader *psColor;
	ID3D11Buffer *vbBlock;
	ID3D11Buffer *vbCylinder;
	DirectX::XMMATRIX viewProjMatrix;
	ID3D11VertexShader *vsColor;

	// Methods
	HRESULT InitializeBlockVertices();
	HRESULT InitializeCylinderVertices();
	void OnDrawFrame();
	HRESULT OnInitialize();
	HRESULT OnLeftMouseDown(int x, int y);
	HRESULT OnMouseMove(int x, int y);
	HRESULT OnMouseWheel(int x, int y, float delta);
	HRESULT OnResize();
	HRESULT OnRightMouseDown(int x, int y);
	HRESULT OnRightMouseUp(int x, int y);

public:
	// Constructor/destructor
	CheckersApp();
	virtual ~CheckersApp();

	// Getters
	ID3D11Buffer *CBPerObject() const { return cbPerObject; }
	ID3D11Buffer *IBBlock() const { return ibBlock; }
	ID3D11Buffer *IBCylinder() const { return ibCylinder; }
	ID3D11InputLayout *InputLayout() const { return inputLayout; }
	ID3D11PixelShader *PSColor() const { return psColor; }
	ID3D11Buffer *VBBlock() const { return vbBlock; }
	ID3D11Buffer *VBCylinder() const { return vbCylinder; }
	const DirectX::XMMATRIX & ViewProjMatrix() const { return viewProjMatrix; }
	ID3D11VertexShader *VSColor() const { return vsColor; }

	// Methods
	void StartAnimation(Animation *animation) { animations.push_back(animation); animation->Start(); }

	// Vertex structure
	struct Vertex
	{
		DirectX::XMFLOAT3 pos;
	};

	// Constant buffer
	struct ObjectParams
	{
		DirectX::XMMATRIX g_worldViewProj;
		DirectX::XMFLOAT3 g_color;
	};
};